// JavaScript Document
var currentDestinationColumn;
function uploadFile(destinationColumn){
	currentDestinationColumn = destinationColumn;
	window.open ("../FCKeditor/editor/filemanager/browser/default/XpressoBrowser.html", 
				 "FileUploadWindow","width=300,height=50, status=0,toolbar=0");

}

function changeFile(fileName){
	document.getElementById("UploadSpan" + currentDestinationColumn).innerHTML = getMediaPreview(fileName) +
		'<br><a href="javascript:uploadFile(' + currentDestinationColumn + ')"> Cambiar imagen ...</a>';
	
	document.getElementById("UploadField" + currentDestinationColumn).value = '..' + fileName;
	
}

function getMediaPreview(filename){
		var mediaPreview = '<a href="javascript:openMediaWindow(' + '\'' + '..' + filename + '\'' + ')">';
		var extension = filename.substring(filename.length - 4, filename.length);
		if (extension != null){
			if (extension.toUpperCase() == ".GIF" || extension.toUpperCase() == ".JPG"){
				var iWidth = document.getElementById("width" + currentDestinationColumn).value;
				var iHeight = document.getElementById("height" + currentDestinationColumn).value;
				mediaPreview = mediaPreview  + '<img src="../' +  filename + '" border=0 width="' + iWidth
					+ '" height="' + iHeight + '">';
			} else if (extension.toUpperCase() == ".SWF" || extension.toUpperCase() ==".FLV"){
				mediaPreview = mediaPreview  + '<img src="../html/images/FlashMovie.gif" border=0>';
			}
		} else {
			return "?";
		}
		mediaPreview = mediaPreview + '</a>';
		return mediaPreview;
}

function openMediaWindow(filename){
	filename = filename.substring(0, filename.indexOf('thumb') - 1);
	window.open (filename, 
				 "FileUploadWindow","width=600,height=400, status=0,toolbar=0,resizable=1");
}